import React from "react";

export default class LifeCom extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 100,
    };
  }

  componentWillMount() {
    console.log("componentWillMount", "16.0之前17用UNSAFE 18就没有了");
  }

  componentDidMount() {
    console.log("componentDidMount");
  }

  shouldComponentUpdate() {
    console.log("shouldComponentUpdate");
    return true;
  }

  UNSAFE_componentWillUpdate() {
    console.log("componentWillUpdate", "16.0之前17用UNSAFE 18就没有了");
  }

  componentDidUpdate() {
    console.log("componentDidUpdate");
  }

  UNSAFE_componentWillReceiveProps() {
    console.log("componentWillReceiveProps", "16.0之前17用UNSAFE 18就没有了");
  }

  componentWillUnmount() {
    console.log("componentWillUnmount");
  }

  lifeClick = () => {
    this.setState({ count: 2 });
  };
  clickTitle = () => {
    this.props.clickTitles("我是儿子的数据");
  };

  render() {
    const { count } = this.state;
    return (
      <div>
        <h1>react的生命周期函数:{count + "-" + this.props.title}</h1>
        <button onClick={this.lifeClick}>life按钮</button>
        <button onClick={this.clickTitle}>修改title子组件</button>
      </div>
    );
  }
}
